package com.katze.boot.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.katze.boot.system.dao.UserRoleMapper;
import com.katze.boot.system.domain.UserRole;
import com.katze.boot.system.service.UserRoleService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

@Service("userRoleService")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService {

	@Override
	@Transactional
	public void deleteUserRolesByRoleId(String[] roleIds) {
		Arrays.stream(roleIds).forEach(id -> baseMapper.deleteByRoleId(Long.valueOf(id)));
	}

	@Override
	@Transactional
	public void deleteUserRolesByUserId(Long... userIds) {
		for (Long userId : userIds) {
			baseMapper.deleteByUserId(userId);
		}
	}

	@Override
	public List<String> findUsernameByRoleId(String... roleIds) {
		return this.baseMapper.findUsernameByRoleId(roleIds);
	}

}
